package vcsn.entities;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;

import vcsn.Config;

public class RenameOperation extends ConflictOperation{
	
	public String originIdentifier;
	public String modifiedIdentifier;
	private boolean isOverPosition;
	
	public String getOriginIdentifier(){return originIdentifier;}
	public String getModifiedIdentifier(){return modifiedIdentifier;}
	public void setOriginIdentifier(String value){originIdentifier = value;}
	public void setModifiedIdentifier(String value){modifiedIdentifier = value;}
	
	public RenameOperation(){
		super();
	}
	public RenameOperation(String appendCommentString){
		super(appendCommentString);
	}
	@Override
	public StringBuilder change(StringBuilder outputBuffer) {
		String identifier = modifiedIdentifier.split("\\.")[modifiedIdentifier.split("\\.").length - 1].trim();
		System.out.println("Refactored name: " + identifier);
		
		if(isOverPosition){
			int pos = outputBuffer.lastIndexOf(originIdentifier);
			int endPos = pos + originIdentifier.length();
			outputBuffer.replace(pos, endPos, identifier);
		}else{
			outputBuffer.append(identifier);
//			System.out.println("After appended source: \n" + outputBuffer.toString());
		}
		return outputBuffer;
	}
	
	public boolean isOverPosition(int currentPositionOfProcess){
		if(currentPositionOfProcess < this.conflictLocatedPosition){
			isOverPosition = false;
		}else{
			isOverPosition = true;
		}
		return isOverPosition;
	}
}
